package com.xhwl.data.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhwl.common.dto.cent.sdata.SpaceFunctionTypeDTO;
import com.xhwl.common.pojo.cent.sdata.SpaceFunctionType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * @Author yf
 * @Description:
 * @Date Create in 10:33 2022/06/07
 */
@Repository
public interface SpaceFunctionTypeDao extends BaseMapper<SpaceFunctionType> {
    /**
     * 检查名称是否唯一
     *
     * @param dto
     * @return
     */
    @Select("<script>select ifnull(count(id),0) from `cent_sdata`.`sdata_space_function_type`" +
            "where is_deleted = 0 and name = #{name} " +
            "and enterprise_id = #{enterpriseId} " +
            "<if test=\" id !=null  \"> and id != #{id}</if></script>")
    Integer checkUniqueName(SpaceFunctionTypeDTO dto);

    /**
     * 检查编码是否唯一
     *
     * @param dto
     * @return
     */
    @Select("select ifnull(count(id),0) from `cent_sdata`.`sdata_space_function_type`" +
            "where is_deleted = 0 and code = #{code} " +
            "and enterprise_id = #{enterpriseId}")
    Integer checkUniqueCode(SpaceFunctionTypeDTO dto);

    /**
     * 获取当前id
     *
     * @return
     */
    @Select("select max(id) + 1 currentId from `cent_sdata`.`sdata_space_function_type`")
    Integer getCurrentId();
}
